<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>用户登录</title>
    <link rel="stylesheet" href="assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="assets/css/login.css">
</head>
<body>
<div class="login-wrapper">
    <!--<div class="login-header">
        <img src="assets/images/logo.png"> EasyWeb后台开发框架
    </div>-->
    <div class="login-body">
        <div class="layui-card">
            <div class="layui-card-header">
                <i class="layui-icon layui-icon-engine"></i>&nbsp;&nbsp;用户登录
            </div>
            <form class="layui-card-body layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-username"></i></label>
                    <div class="layui-input-block">
                        <input name="account" type="text" placeholder="账号" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><i class="layui-icon layui-icon-password"></i></label>
                    <div class="layui-input-block">
                        <input name="password" type="password" placeholder="密码" class="layui-input"
                               lay-verify="required" required/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <button lay-filter="login-submit" class="layui-btn layui-btn-fluid" lay-submit>登 录</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script type="text/javascript" src="assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="assets/js/store2.js"></script>
<script type="text/javascript" src="assets/js/custom.js"></script>
<script>
    layui.config({
        base: 'assets/module/'
    }).use(['layer', 'form', 'config'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var config = layui.config;

        if (config.getToken()) {
            goIndex();
        }
        // 表单提交
        form.on('submit(login-submit)', function (obj) {
            loadWait();
            $.ajax({
                url: config.base_server + 'user/login',
                type: "post",
                data: JSON.stringify(obj.field),
                contentType: "application/json;charset=utf-8",
                dataType: "json",
                success: function (data) {
                    if(data.code == 200 || data.code == 0){
                        // 保存字典数据
                        //store.set('dict', data.dict);

                        // 保存token
                        config.putToken(data.data);
                        success(data.msg, {icon: 1, time: 1500}, function () {
                            goIndex();
                        });
                    } else {
                        error(data.msg);
                    }
                },
                error: function(jqXHR, textStatus, errorThrown){
                    if(jqXHR.hasOwnProperty("responseJSON")){
                        var json = jqXHR.responseJSON;
                        if(json.hasOwnProperty("msg")){
                            error(json.msg);
                        }
                    }
                },
                complete: function () {
                    closeLoadWait();
                }
            });

            return false;
        });

        function goIndex() {
            location.replace('/webapp2/index.html');
        }
    });
</script>
</body>
</html>